<?
class printLabel extends yellowpages{
 var $lang;
 var $type;
 
 function printLabel($lang, $type){
  $this->lang = $lang;
  $this->type = $type;
 }
 
 function sql($a='',$kind){ //echo($a);
  switch($kind){
   case 'print':
    $sql = "select company_".$this->lang.",company_add_".$this->lang.",town_name_".
			$this->lang.", tel_fax, email_address,internet_address, profile_".$this->lang." 
			from company_name, company, no_tel, company_notes, town
			where (company_name.idall=company.company_id) and 
			(company_name.idall=no_tel.idall) and 
			(company_name.idall = company_notes.company_id) and 
			(company_name.town_id = town.town_id) and (company_name.idall = $a)";
	break;
   case 'label':
    $sql = "select company_".$this->lang.", company_add_".$this->lang.", town_name_".$this->lang." 
			from company_name, company, town
			where (company_name.idall=company.company_id) and 
			(company_name.town_id = town.town_id) and (company_name.idall = $a)";
	break;
   case 'class':
    $sql = "SELECT class_name_".$this->lang." FROM class,id_class 
           WHERE (class.class_id = id_class.class_id_1) and(company_id=$a) and sort_no=1";		   
	break;
  }
//  echo("<br>$sql<br>");
  return mysql_query($sql);
 }
 
 function output(){
  $a = func_get_args(); //print_r($a);
  $k = $a[0]; $j=0; $tr ='';
  if(strpos($a[0],"|")>0) $k = explode("|",$a[0]);
  $t = "<table class=tab cellpadding=0 cellspacing=0 width=100%>";
  if(is_array($k)){
   for($i=0;$i<count($k);$i++){// echo($k[$i]."<br>");
	$result = $this->sql($k[$i],$this->type);
	while($rs = mysql_fetch_array($result, MYSQL_NUM)){
	 if($this->type!='label'){ $j=0; $tr="</tr><tr><td height=18><hr></td></tr>";}
	 if($j==0){
	  $t .= "<tr>".$this->makeResult($rs,$k[$i]).$tr; $j=1;
	 }else{
	   $t .= $this->makeResult($rs,$k[$i])."</tr><tr><td height=18></td></tr>"; $j=0;
	 }
	}//end while
	mysql_free_result($result);
   }
  }else{
   $result = $this->sql($k,$this->type);
	while($rs = mysql_fetch_array($result, MYSQL_NUM))
	  $t .= "<tr>".$this->makeResult($rs,$k)."<td width=50%>&nbsp;</td></tr><tr><td height=18></td></tr>";
	mysql_free_result($result);
  }
  echo("$t</table>");
 }
 
 function makeResult($rs,$_id=''){
  $rs[1] = explode("|",$rs[1]);
  $a = $this->changLang($this->lang);
//  print_r($rs[1]);
  if(strpos($rs[1][3],";")==0) $rs[1][3] = str_replace(";",",",$rs[1][3]);
  if($this->type=='label'){
   $add = trim($rs[1][0]." ".$rs[1][1]." ".$rs[1][2]." ".$rs[1][3]." ".$rs[1][4]);
   $d = trim($rs[1][5].$rs[1][6]);
   if($this->lang!='cn'){
    $add = substr($add,0,strlen($add)-1);
    $d = substr($d,0,strlen($d)-1);
   }
   $t = "<td valign=top><table class=tab cellpadding=0 cellspacing=0 width=100%>
   		<tr><td><b>$rs[0]</b></td></tr>
		<tr><td>".$add."</td></tr>
		<tr><td>".$d."</td></tr>
		<tr><td>$rs[2], VIETNAM</td></tr></table>
		</td>";
  }else{
   $add = $rs[1][0]." ".$rs[1][1]." ".$rs[1][2]." ".$rs[1][3]." ".$rs[1][4].$rs[1][5].$rs[1][6];
   $add = trim($add);
   if($this->lang=='cn') 
    $rs[1] = $add;
   else
    $rs[1] = substr($add,0,strlen($add)-1);
   $tel="$a[0]$rs[3]"; $fax="";
   if(strpos($rs[3],"|")>0){
    $rs[3] = explode("|",$rs[3]); $tel=$a[0].$rs[3][0]; 
	if($rs[3][1]) $fax=$a[1].$rs[3][1];
   }
   if(trim($rs[4])) $rs[4] = "$a[2]$rs[4]";
   if(trim($rs[5])) $rs[5] = "$a[3]$rs[5]";
   $t = "<td valign=top><table class=tab cellpadding=0 cellspacing=0 width=100%>
   		<tr><td colspan=2><b>$rs[0]</b></td></tr>
		<tr><td colspan=2>$rs[1]</td></tr>
		<tr><td width=50% nowrap>$tel</td><td nowrap>$fax</td></tr>
		<tr><td nowrap>$rs[4]</td><td nowrap>$rs[5]</td></tr>
		<tr><td colspan=2>$rs[6]</td></tr>
		<tr><td colspan=2>$a[4]".$this->getClass($_id)."</td></tr>
		</table></td>";
  }
  return $t;
 }
 
 function changLang($lng){
  $a = array();
  switch($lng){
   case "us":
    $a[]="Tel: "; $a[]="Fax: "; $a[]="Email: "; $a[]="Website: "; $a[]="Categories: ";
    break;
   case "vn":
    $a[]="Điện Thoại: "; $a[]="Fax: "; $a[]="Email: "; $a[]="Website: "; $a[]="Nghành nghề: ";
	break;
   default:
    $a[]="Tel: "; $a[]="Fax: "; $a[]="Email: "; $a[]="Website: "; $a[]="黄页分类: ";
  }
  return $a;
 }
 
 function getClass($_id){
  $result = $this->sql($_id,'class');
  $rs = mysql_fetch_array($result,MYSQL_NUM);
  $t = $rs[0];
  mysql_free_result($result);
  return $t;
 }
 
}
?>